package com.trkj;

import com.trkj.entity.BaseDao;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class zy {
    private static Logger logger= LogManager.getLogger(zy.class);
    @Test
    public void zy() throws SQLException {
        BaseDao baseDao = new BaseDao();
        Connection connection = baseDao.getConnection();
        if (connection != null) {
            logger.debug("成功建立数据库连接！");
            // 这里可以进行一些数据库操作的测试
            String sql="insert into emp values (1,'name',1,1)";
            Statement statement = connection.createStatement();
            int rowsAffected = statement.executeUpdate(sql);

            if (rowsAffected > 0) {
                logger.debug("成功添加记录");
            } else {
                logger.debug("添加失败");
            }
        } else {
            logger.debug("无法建立数据库连接！");
        }
    }
}
